/**
 * 
 */
package optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator.mutation;

import optimization.naturalOptimization.evolutionaryAlgorithm.EvolutionaryAlgorithm;
import optimization.naturalOptimization.population.individual.EA.DoubleArrayEAIndividual;

/**
 * This class provides the mutation of an double array position with a double
 * array strategy component.
 * 
 * @author Kevin Wagner
 * @version 1.0
 */
public class DoubleArrayMutation extends Mutator {

	/**
	 * Creates a new mutator.
	 * 
	 * @param parentEA
	 */
	public DoubleArrayMutation(EvolutionaryAlgorithm parentEA) {
		super(parentEA);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator
	 * .EvolutionaryOperator#work()
	 */
	@Override
	public void work() {
		for (int i = 0; i < getParentEA().getLambda(); i++) {
			DoubleArrayEAIndividual ind = (DoubleArrayEAIndividual) getParentEA()
					.getProgenyPopulation().getIndividual(i);
			double[] newPos = ind.getPosition().clone();
			for (int j = 0; j < ind.getPosition().length; j++) {
				newPos[j] += getParentEA().getRng().nextGaussian()
						* ind.getStrategyComponent()[j];
			}
			ind.setPosition(newPos.clone());
		}

	}

}
